package DBClasses;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;

@PersistenceCapable(identityType = IdentityType.UNSPECIFIED)
public class Game
{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	public Long getId()
	{
		return id;
	}

	@Unique
	@Persistent
	private String name;

	public String getName()
	{
		return name;
	}

	public enum PriceTypes {
		Dollar, Euro, Rubl
	};

	@Persistent
	private Float price;

	public Float getPrice(PriceTypes pr_type)
	{
		switch (pr_type) {
		case Dollar:
			return price / (float) 30;
		case Euro:
			return price / (float) 40;
		case Rubl:
			return price;
		default:
			return price;
		}
	}

	public void setPrice(float ft)
	{
		price = ft;
	}

	@Persistent
	private String adder;

	public String getAdder()
	{
		return adder;
	}

	@Persistent
	private String type;

	public String getGameType()
	{
		return type;
	}

	public void setGameType(String gt)
	{
		type = gt;
	}

	@Persistent
	private Date add_date;

	public Date getAddDate()
	{
		return add_date;
	}

	@Persistent
	private String description;

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String dscr)
	{
		description = dscr;
	}

	@Persistent
	private String img_id;

	public String getImg()
	{
		return img_id;
	}

	public void setImg(String img)
	{
		img_id = img;
	}

	@Persistent
	private List<String> scrns;

	public List<String> getScrns()
	{
		return scrns;
	}

	public void setScrns(List<String> scrnss)
	{
		for (String string : scrnss)
		{
			this.scrns.add(string);
		}
	}

	public Game(String name, Float price, String type, String adder,
			String description, String img_id, List<String> scrnss)
	{
		this.name = name;
		this.price = price;
		this.type = type;
		this.adder = adder;
		this.add_date = Calendar.getInstance().getTime();
		this.description = description;
		this.img_id = img_id;
		this.scrns = new ArrayList<String>();
		for (String string : scrnss)
		{
			this.scrns.add(string);
		}
	}
}
